package com.cckat.service.impl;

import com.cckat.base.BaseMapper;
import com.cckat.base.BaseServiceImpl;
import com.cckat.entity.Permission;
import com.cckat.helper.PermissionHelper;
import com.cckat.mapper.PermissionMapper;
import com.cckat.service.PermissionService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 静海基地
 */
@DubboService
public class PermissionServiceImpl extends BaseServiceImpl<Permission> implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;


    @Override
    public BaseMapper<Permission> getBaseMapper() {
        return permissionMapper;
    }


    @Override
    public List<Permission> findMenuListByAdminId(Long adminId) {
        //先根据用户id查询所拥有的权限的集合
        List<Permission> originalPermissionList = permissionMapper.findPermissionListByAdminId(adminId);
        //根据PermissionHelper获取权限菜单的层级关系
        List<Permission> permissionList = PermissionHelper.build(originalPermissionList);

        return permissionList;
    }

    @Override
    public List<String> findPermissionCodeListByAdminId(Long adminId) {
        return permissionMapper.findPermissionCodeListByAdminId(adminId);
    }
}
